package com.servicio.common.data;

import java.io.File;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

	private static final SessionFactory sessionFactory = buildSessionFactory();

	private static SessionFactory buildSessionFactory() {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
				Configuration cfg = new Configuration().configure(new File("resources/hibernate.cfg.xml"));
				cfg.setProperty("connection.url", "jdbc:mysql://servicio.servehttp.com/data");
				//cfg.setProperty("connection.url", "jdbc:mysql://192.168.1.100/data");
				cfg.setProperty("connection.username", "root");
				cfg.setProperty("connection.password", "1q2w3e4r");
				SessionFactory sessionFactory = cfg.buildSessionFactory();
				/*SessionFactory sessionFactory = new Configuration().configure(new File(
					"resources/hibernate.cfg.xml"))
					.buildSessionFactory();*/
			return sessionFactory;
		} catch (Throwable ex) {
			// Make sure you log the exception, as it might be swallowed
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

}
